package com.sfh.cpc.user;

import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.sfh.cpc.BaseSwipeRefreshMoreLayoutFragment;
import com.sfh.cpc.R;
import com.sfh.cpc.com.entity.EMass;
import com.sfh.cpc.com.entity.ENote;
import com.sfh.cpc.com.entity.EUser;
import com.sfh.cpc.com.entity.RspPage;
import com.sfh.cpc.com.entity.RxEventSearch;
import com.sfh.cpc.com.refresh.SwipeRefreshMoreLayout;
import com.sfh.cpc.com.server.INoteServer;
import com.sfh.cpc.home.adapter.WealthAdapter;
import com.sfh.cpc.mass.MassSearchFragment;
import com.sfh.cpc.mass.model.MassModel;
import com.sfh.cpc.note.NoteActivity;
import com.sfh.cpc.user.model.UserModel;
import com.sfh.lib.AppCacheManager;
import com.sfh.lib.event.RxBusEvent;
import com.sfh.lib.mvvm.annotation.LiveDataMatch;
import com.sfh.lib.ui.AbstractLifecycleFragment;

/**
 * 功能描述:搜索用户
 *
 * @author SunFeihu 孙飞虎
 * @date 2019/6/11
 */
public class UserSearchFragment extends BaseSwipeRefreshMoreLayoutFragment<UserModel> {
    @Override
    public String getName() {
        return "用户";
    }
    public static UserSearchFragment newFragment() {
        return new UserSearchFragment();
    }

    private String content = "";

    @Override
    public BaseQuickAdapter getAdapter() {
        this.onAutoRefresh = false;
        return new WealthAdapter();
    }

    @Override
    public void loadPage(int nowPage) {
        this.activateLifecycleEvent();
        this.getViewModel().querySearchUser(nowPage, content);
    }

    @RxBusEvent(from = "搜索")
    public void onRxEventSearch(RxEventSearch data) {
        content = data.content;
        swipeRefreshMoreLayout.onAutoRefresh();
    }

    @LiveDataMatch
    public void onPageSuccess(RspPage<EUser> data) {

        super.onPageData(data);
    }


    @Override
    public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
        INoteServer noteServer = AppCacheManager.getCache(INoteServer.class.getSimpleName(), INoteServer.class);
        if (noteServer != null) {
            EUser user = (EUser) adapter.getItem(position);
            noteServer.openUserNote(getContext(), user.getUserId());
        }
    }
}

